﻿using Common.Communal;
using ERP.Domain.System;
using MediatR;
using SqlSugar;
using System.Api.Read.Applications.Commands.Organizes;

namespace System.Api.Read.Applications.CommandHandlers.Organizes
{
    public class OrganizeTypeQueryCommandHandler : IRequestHandler<OrganizeTypeQueryCommand, ApiResult<List<OrganizeType>>>
    {
        private readonly ISqlSugarClient sqlSugar;

        public OrganizeTypeQueryCommandHandler(ISqlSugarClient sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }

        public Task<ApiResult<List<OrganizeType>>> Handle(OrganizeTypeQueryCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<OrganizeType>> result = new ApiResult<List<OrganizeType>>();
            var res = sqlSugar.Queryable<OrganizeType>().ToList();
            result.Success(res, "组织类型获取成功");
            return Task.FromResult(result);
        }
    }
}
